package com.lqwu.mallchatserver.common.utils;

import com.lqwu.mallchatserver.common.domain.dto.RequestInfo;

/**
 * 请求上下文
 */
public class RequestHolder {
    /**
     * 当前线程的请求信息
     * @return
     */
    private static final ThreadLocal<RequestInfo> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 设置请求信息
     * @param requestInfo
     */
    public static void set(RequestInfo requestInfo) {
        THREAD_LOCAL.set(requestInfo);
    }

    /**
     * 获取请求信息
     * @return
     */
    public static RequestInfo get() {
        return THREAD_LOCAL.get();
    }

    /**
     * 移除请求信息（防内存泄露）
     */
    public static void remove() {
        THREAD_LOCAL.remove();
    }
}
